package com.bdy.lm.taximanager.model;

import com.bdy.lm.taximanager.app.MyApp;
import com.bdy.lm.taximanager.util.TimeUtils;

import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by liming on 2017/6/1 0001.
 *  串口数据
 */

public class SerialPortData {

    public static final String run = "run";
    public static final String noneRun = "noneRun";
    private TransitionData transitionData = new TransitionData();
    private QueryMeterPointData queryMeterPointData = new QueryMeterPointData();
    private GetupData getupData = new GetupData();

    public static SerialPortData serialPortData;

    /**
     * 获取唯一单例
     * @return
     */
    public static SerialPortData getInstance() {
        if(serialPortData == null) {
            serialPortData = new SerialPortData();
            return serialPortData;
        } else {
            return serialPortData;
        }
    }
    private SerialPortData(){}

    public static class TransitionData {

        private String license;//车牌号
        private String tradePermission;//经营许可证号
        private String employId;//驾驶员从业资格证号
        private String up;//上车时间
        private String down;//下车时间
        private double sum;//金额
        private double price;//单价
        private double distance;//总里程
        private String spentTime;//用时
        private double fuelSurcharge;//燃油附加费
        private String waitTime;//等待计时
        private String transitionType;//交易类型
        private int currentRunTime;//当前车次
        private int hour;
        private int minute;
        private double nRun;//空驶里程
        private String runState;
        private String evaluate;
        public List<LocationTrack> locationTracks;
        private Map<String, Object> transInfo = new HashMap<String, Object>();

        public String getUp() {
            return up;
        }

        public void setUp(String up) {
            this.up = up;
        }

        public String getDown() {
            return down;
        }

        public void setDown(String down) {
            this.down = down;
        }

        public double getSum() {
            return sum;
        }

        public void setSum(double sum) {
            this.sum = sum;
        }

        public double getPrice() {
            return price;
        }

        public void setPrice(double price) {
            this.price = price;
        }

        public double getDistance() {
            return distance;
        }

        public void setDistance(double distance) {
            this.distance = distance;
        }

        public String getSpentTime() {
            return spentTime;
        }

        public void setSpentTime(String spentTime) {
            this.spentTime = spentTime;
        }

        public double getFuelSurcharge() {
            return fuelSurcharge;
        }

        public void setFuelSurcharge(double fuelSurcharge) {
            this.fuelSurcharge = fuelSurcharge;
        }

        public String getWaitTime() {
            return waitTime;
        }

        public void setWaitTime(String waitTime) {
            this.waitTime = waitTime;
        }

        public String getTransitionType() {
            return transitionType;
        }

        public void setTransitionType(String transitionType) {
            this.transitionType = transitionType;
        }

        public int getCurrentRunTime() {
            return currentRunTime;
        }

        public void setCurrentRunTime(int currentRunTime) {
            this.currentRunTime = currentRunTime;
        }

        public int getHour() {
            return hour;
        }

        public void setHour(int hour) {
            this.hour = hour;
        }

        public int getMinute() {
            return minute;
        }

        public void setMinute(int minute) {
            this.minute = minute;
        }

        public double getnRun() {
            return nRun;
        }

        public void setnRun(double nRun) {
            this.nRun = nRun;
        }

        public String getRunState() {
            return runState;
        }

        public void setRunState(String runState) {
            this.runState = runState;
        }

        public String getEvaluate() {
            return evaluate;
        }

        public void setEvaluate(String evaluate) {
            this.evaluate = evaluate;
        }

        public List<LocationTrack> getLocationTracks() {
            return locationTracks;
        }

        public void setLocationTracks(List<LocationTrack> locationTracks) {
            this.locationTracks = locationTracks;
        }
        public String getLicense() {
            return license;
        }

        public void setLicense(String license) {
            this.license = license;
        }

        public String getTradePermission() {
            return tradePermission;
        }

        public void setTradePermission(String tradePermission) {
            this.tradePermission = tradePermission;
        }

        public String getEmployId() {
            return employId;
        }

        public void setEmployId(String employId) {
            this.employId = employId;
        }
        public Map<String, Object> getTransInfo() {

			DecimalFormat df = new DecimalFormat("######0.00");
            transInfo.put("getOnTime", up);
            transInfo.put("getOffTime", down);
            transInfo.put("spendTime", spentTime);
            transInfo.put("money", df.format(sum));
            transInfo.put("distance", df.format(distance));
            transInfo.put("nullRun", df.format(nRun));
            transInfo.put("fuelSurcharge", df.format(fuelSurcharge));
            transInfo.put("waitTime", waitTime);
            transInfo.put("transitionType", transitionType);
            transInfo.put("currentRunTime", Integer.toString(currentRunTime));
            transInfo.put("evaluate", evaluate);
            transInfo.put("license", license);
            if (TimeUtils.isNight().equals("昼间")) {
                transInfo.put("price", MyApp.fare.getPriceDay());
            } else {
                transInfo.put("price", MyApp.fare.getPriceNight());
            }
            transInfo.put("journey", runState);
            if((MyApp.transitionNum % 1 == 0) && (locationTracks != null) && (locationTracks.size() > 0)) {
                transInfo.put("locationTracks", locationTracks);
            }
            //System.out.println("upload" + transInfo.toString());
            return transInfo;
        }

        @Override
        public String toString() {
            return "TransitionData{" +
                    "up='" + up + '\'' +
                    ", down='" + down + '\'' +
                    ", sum=" + sum +
                    ", price=" + price +
                    ", distance=" + distance +
                    ", spentTime='" + spentTime + '\'' +
                    ", fuelSurcharge=" + fuelSurcharge +
                    ", waitTime='" + waitTime + '\'' +
                    ", transitionType='" + transitionType + '\'' +
                    ", currentRunTime=" + currentRunTime +
                    ", hour=" + hour +
                    ", minute=" + minute +
                    ", nRun=" + nRun +
                    ", runState='" + runState + '\'' +
                    ", evaluate='" + evaluate + '\'' +
                    ", transInfo=" + transInfo +
                    '}';
        }
    }

    public static class QueryMeterPointData {
        private String queryTime;
        private double meterPoint;
        private String license;//车牌号

        public String getLicense() {
            return license;
        }

        public void setLicense(String license) {
            this.license = license;
        }

        public String getQueryTime() {
            return queryTime;
        }

        public void setQueryTime(String queryTime) {
            this.queryTime = queryTime;
        }

        public double getMeterPoint() {
            return meterPoint;
        }

        public void setMeterPoint(double meterPoint) {
            this.meterPoint = meterPoint;
        }

        @Override
        public String toString() {
            return "QueryMeterPointData{" +
                    "queryTime='" + queryTime + '\'' +
                    ", meterPoint=" + meterPoint +
                    '}';
        }
    }

    public static class GetupData {
        private String up;//上车时间
        private String runState;

        public String getUp() {
            return up;
        }

        public void setUp(String up) {
            this.up = up;
        }

        public String getRunState() {
            return runState;
        }

        public void setRunState(String runState) {
            this.runState = runState;
        }

        @Override
        public String toString() {
            return "GetupData{" +
                    "up='" + up + '\'' +
                    ", runState='" + runState + '\'' +
                    '}';
        }
    }

    //外部类成员get set


    //内部类get set
    public TransitionData getTransitionData() {
        return transitionData;
    }

    public void setTransitionData(TransitionData transitionData) {
        this.transitionData = transitionData;
    }

    public QueryMeterPointData getQueryMeterPointData() {
        return queryMeterPointData;
    }

    public void setQueryMeterPointData(QueryMeterPointData queryMeterPointData) {
        this.queryMeterPointData = queryMeterPointData;
    }

    public GetupData getGetupData() {
        return getupData;
    }

    public void setGetupData(GetupData getupData) {
        this.getupData = getupData;
    }

    @Override
    public String toString() {
        return "SerialPortData{" +
                ", transitionData=" + transitionData +
                ", queryMeterPointData=" + queryMeterPointData +
                ", getupData=" + getupData +
                '}';
    }
}
